package com.arcsoft.crud.limitNumber.task;

import java.util.Date;

import com.arcsoft.crud.Constants.Global;
import com.arcsoft.crud.limitNumber.base.BenchmarkBase;
import com.arcsoft.crud.limitNumber.base.BenchmarkTask;
import com.arcsoft.crud.util.ConnectionDB;
import com.arcsoft.log.entity.OptimizeAnalyzeLog;

public class InsertTask extends BenchmarkTask {

	public InsertTask(int index, BenchmarkBase parent, int printInfoInterval, long loopCount, String taskLogTable) {
		super(index, parent, printInfoInterval, loopCount, taskLogTable);
	}

	@Override
	public String execute(int loopIndex){
        ConnectionDB db = new ConnectionDB();
        
        String sql = "insert into people(name, age,password,name1,password1,name2,score,score1,score2,score4) values(?,?,?,?,?,?,?,?,?,?)";
        Object arrays[] = {"jack"+threadIndex+""+loopIndex, (int)Math.random()*100,
			        		randomString((int)Math.random()*10),randomString((int)Math.random()*10),
			        		randomString((int)Math.random()*10),randomString((int)Math.random()*10),
			        		Math.random()*100,Math.random()*100,randomString((int)Math.random()*10),randomString((int)Math.random()*10)
			        	  };
        db.updateBySql(sql, arrays);
        return parseSql(sql, arrays);
	}
	
	@Override
	public void logInfo(Date startTime, Date endTime, String requestDetail, int extendTime){
		
		String sceneDesc = Global.OPERATOR_TYPE_INSERT+"-"+Global.THREAD_COUNT+"C-"+Global.LOOP_COUNT+"L";//场景名命名规则 操作类型-并发数C-循环次数L
		
		OptimizeAnalyzeLog optimizeAnalyzeLog = new OptimizeAnalyzeLog
					(sceneDesc,Global.OPERATOR_TYPE_INSERT,startTime, endTime, extendTime, requestDetail);
		
		insertLog(optimizeAnalyzeLog);
	}
}
